package com.djf.djfauth.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.djf.djfauth.entity.User;
import com.djf.djfauth.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author 26393
 * @Date 2025/7/7 2:18
 * @Version 1.0
 */@Service
public class UserService {
    @Resource
    private UserMapper userMapper;

    public User findByUsername(String username) {
        return userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getUsername, username));
    }

    public User findById(Long userId) {
        return userMapper.selectById(userId);
    }

    public Long createUser(String username, String nickname, String avatar) {
        User user = new User();
        user.setUsername(username);
        user.setNickname(nickname);
        user.setAvatar(avatar);
        userMapper.insert(user);
        return user.getId();
    }
}
